package org.itstack.demo.design.door.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: fanYuLe
 * @CreateTime: 2023-12-21  15:26
 * @Description: ⾃定义配置类信息获取  是对配置的获取操作，主要是对注解的定
 * 义； @Configuration 、 @ConditionalOnClass 、 @EnableConfigurationProperties ，这
 * ⼀部分主要是与SpringBoot的结合使⽤。
 */
@Configuration
@ConditionalOnClass(StarterService.class)
@EnableConfigurationProperties(StarterServiceProperties.class)
public class StarterAutoConfigure {

    @Autowired
    private StarterServiceProperties properties;

    // prefix为配置文件中的前缀,
    // name为配置的名字
    // havingValue是与配置的值对比值,当两个值相同返回true,配置类生效.
    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "itstack.door",value = "enabled",havingValue = "true")
    StarterService starterService(){
        String userStr = properties.getUserStr();
        return new StarterService(properties.getUserStr());}
}
